<template>
	<!-- 维修管理/电梯大修 -->
	<div class="operationBox heightMax publicbox" v-loading='loading'>
		<el-row :gutter="10">
			<el-col :span="6">
				<div class="colItem">
					<span class="font14 searchCode" style="width: 200px;">设备注册代码：</span>
					<el-input size="mini" @keyup.enter.native="find" placeholder="请输入设备注册代码" clearable v-model="marketingCode"></el-input>
				</div>
			</el-col>
			<el-col :span="5">
				<div class="colItem">
					<span class="font14 searchCode">开始时间：</span>
					<el-date-picker v-model="timeStart" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择开始日期"
					 size="mini">
					</el-date-picker>
				</div>
			</el-col>
			<el-col :span="5">
				<div class="colItem">
					<span class="font14 searchCode">结束时间：</span>
					<el-date-picker v-model="timeEnd" type="date" format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder="选择结束日期"
					 size="mini" :disabled="disAbleTime" :picker-options="pickerOptions">
					</el-date-picker>
				</div>
			</el-col>
			<el-button type="primary" icon="el-icon-search" size="mizi" class='fl' @click='find'>搜索</el-button>
			<el-button icon="el-icon-delete" @click='reset' class='fl'>重置</el-button>
		</el-row>
		<!-- 	<div class="listName">
			<i></i><span class="font14">电梯大修列表</span>
		</div> -->
		<el-row :gutter="10">
			<div class="fr">
				<el-button type="primary" @click='derive' v-if="readDataShow">导出</el-button>
				<el-button type="success" @click='newAdd' v-if="addBtnShow">新建</el-button>
			</div>
		</el-row>
		<div class="tableBox">
			<vueScroll>
				<el-table :data="tableData" highlight-current-row ref="moviesTable" @row-click="rowClick" @select-all="selectChange"
				 @selection-change="selectChange" style="width: 100%" border header-row-class-name='tableHeader'>
					<el-table-column type="index" class="over" fixed>
					</el-table-column>
					<el-table-column type="selection" min-width="50" fixed>
					</el-table-column>
					<el-table-column label="电梯注册号" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.register_code" placement="top">
								<span class="speSpan">{{scope.row.register_code}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="状态" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.status" placement="top">
								<span class="speSpan">{{scope.row.status}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="维保单位" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.maintain_company" placement="top">
								<span class="speSpan">{{scope.row.maintain_company}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="使用单位" max-width="120">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.property_company" placement="top">
								<span class="speSpan">{{scope.row.property_company}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="大修项目" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.alarm_position" placement="top">
								<span class="speSpan">{{scope.row.alarm_position}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="大修人员" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.notify_person" placement="top">
								<span class="speSpan">{{scope.row.notify_person}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="计划完成时间" max-width="140">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.end_planning_time" placement="top">
								<span class="speSpan">{{scope.row.end_planning_time}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页器 -->
				<div class="pag">
					<el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="page_size" layout="total, sizes, prev, pager, next, jumper"
					 :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
					</el-pagination>
				</div>
			</vueScroll>
		</div>
		<addAndCompile v-if='addAndCompileShow' :addAndCompileShow='addAndCompileShow' :title='title' @closeMask='closeMask'></addAndCompile>
	</div>
</template>

<script>
	import addAndCompile from "./addAndCompile.vue"
	import {
		loadFn,
		axiosPost,
		axiosGet,
		axiosDelete,
		axiosPut,
		moment
	} from "@/common.js";
	export default {
		mounted() {
			this.getTableList()
			this.getPermition()
		},
		components: {
			addAndCompile,
		},
		data() {
			return {
				marketingCode: '',
				tableData: [],
				page: 1,
				page_size: 10,
				total: 0,
				loading: true,
				timeStart: '',
				timeEnd: '',
				query: '',
				addAndCompileShow: false,
				title: '新建电梯大修',
				pidsArr: [],
				addBtnShow: false,
				complieBtnShow: false,
				deleteBtnShow: false,
				readDataShow: false,
			}
		},
		computed: {
			disAbleTime() {
				if (this.timeStart) {
					return false
				} else {
					return true
				}
			},
			pickerOptions() {
				return {
					disabledDate: (time) => {
						return time.getTime() < moment(this.timeStart)
					}
				}
			},
			xiuArr() {
				if (localStorage.weiXiu) {
					let arr = JSON.parse(localStorage.weiXiu).list
					return arr.filter((item) => {
						return item.name == '普通维修'
					})
				} else {
					return []
				}
			}
		},
		methods: {
			getPermition() {
				if (this.xiuArr.length != 0) {
					if (this.xiuArr[0].pids) {
						this.pidsArr = this.xiuArr[0].pids
					}
				}
				if (this.pidsArr.length > 0) {
					this.pidsArr.map((item) => {
						if (item.desc == 'get') {
							this.readDataShow = true
						}
						if (item.desc == 'put') {
							this.complieBtnShow = true
						}
						if (item.desc == 'delete') {
							this.deleteBtnShow = true
						}
						if (item.desc == 'post') {
							this.addBtnShow = true
						}
					})
				}
			},
			//导出
			derive() {

			},
			//新建一个大修
			newAdd() {
				this.addAndCompileShow = true
				this.title = '新建电梯大修'
			},
			//关闭添加弹窗
			closeMask(value) {
				this.addAndCompileShow = false
				if (value == 2) {
					this.loading = true
					this.getTableList()
				}
			},
			//获取表格数据
			getTableList() {
				let params = {
					page: this.page,
					page_size_count: this.page_size,
					key_words: this.query,
					maintenance_type: 1,
					start_planning_time: this.timeStart ? this.timeStart : '',
					end_planning_time: this.timeEnd ? this.timeEnd : '',
				}
				console.log(this.timeStart)
				console.log(this.timeEnd)
				axiosGet('/manu/elevator/repair/', params, (res) => {
					this.loading = false
					if (res.code == 0) {
						this.total = res.detail.count
						this.tableData = res.detail.results
						this.tableData.map((item) => {
							if (item.status == 10) {
								item.status = '已创建'
							} else if (item.status == 20) {
								item.status = '已确认'
							} else if (item.status == 30) {
								item.status = '已退回'
							} else if (item.status == 40) {
								item.status = '到达现场'
							} else if (item.status == 50) {
								item.status = '问题解决'
							} else if (item.status == 60) {
								item.status = '问题消除'
							}
							return item
						})
						// console.log(this.tableData)
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			find() {
				this.loading = true
				this.getTableList()
			},
			reset() {
				this.loading = true
				this.page = 1
				this.page_size = 10
				this.query = ''
				this.timeStart = ''
				this.timeEnd = ''
				this.getTableList()
			},
			//表格
			rowClick(row, column, event) {
				this.$refs.moviesTable.toggleRowSelection(row)
			},
			selectChange() {

			},
			//分页器
			handleSizeChange(size) {
				this.loading = true
				this.page_size = size
				this.getTableList()
			},
			handleCurrentChange(page) {
				this.loading = true
				this.page = page
				this.getTableList()
			}
		},
	}
</script>

<style scoped lang="less">
	.colItem {
		display: flex;
		flex-direction: row;

		.searchCode {
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			width: 120px;
		}
	}

	.tableBox {
		height: 80%;
		overflow-y: auto;
	}

	.listName {
		display: flex;
		justify-content: flex-start;
		text-align: left;
		height: 25px;
		align-items: center;

		i {
			width: 3px;
			height: 60%;
			background: #2d8cf0;
			margin: 10px 5px;
		}

	}
</style>
